package com.aaa.dem1027.第一遍.d03;

import java.lang.reflect.Method;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/10/27  14:45
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Class<?> aClass = Class.forName("com.aaa.dem1027.d12.dog");

        //1.根据方法名和参数获取本类中指定的方法对象
        Method fun = aClass.getDeclaredMethod("fun");
        System.out.println("fun = " + fun);

        Method sss = aClass.getDeclaredMethod("sss", String.class);
        System.out.println("sss = " + sss);

        //2.  获取到本类中所有的方法
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for(Method method:declaredMethods){
            System.out.println("method = " + method);
        }

        //3. 根据方法名和参数类型获取本类以及父类中指定public的方法对象
        Method fun1 = aClass.getMethod("fun");
        System.out.println("fun1 = " + fun1);
        Method show = aClass.getMethod("show");
        System.out.println("show = " + show);

        //4. 获取本类以及父类中所有public方法对象
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println("method = " + method);
        }
    }
}

class people{

    public void show(){
        System.out.println("show方法");
    }
    public void print(){
        System.out.println("print方法");
    }
}

class dog extends people{
    public void fun(){
        System.out.println("dog的fun方法");
    }
    public void sss(String name){
        System.out.println("dog的sss方法"+name);
    }
}
